package com.company.class10;

/**
 * @Classname RecursionTest
 * @Description 类型说明
 * @Date 2022/5/2 21:16
 * @Created by zbw
 */

public class RecursionTest {
    public static void main(String[] args) {
//        Washmachine wm = new Washmachine();
//        wm.washSelf();
        System.out.println(factorial(7));
        System.out.println(factNoRec(7));
        System.out.println(fib(10));

    }

    //阶乘方法
    public static int factorial(int n){
        int result = 1;
        if(n==1){
            result = 1;
        }else{
            result = n*factorial(n-1);
        }
        return result;
    }

    //非递归处理
    public static int factNoRec(int n){
        int result =1;
        for(int i=n;i>=1;i--){
            result *= i;
        }
        return result;
    }


    //斐波拉及方法
    public static int fib(int n){
        if(n <= 0){
            return -1;
        }else if(n <= 2){
            return 1;
        }else{
            return fib(n-1)+fib(n-2);
        }
    }
}
